package logic

import (
	"context"
	"goodsrpc/goods"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateImgLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateImgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateImgLogic {
	return &UpdateImgLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateImgLogic) UpdateImg(req *types.UpdateImgRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	img, err := l.svcCtx.Goods.UpdateImg(l.ctx, &goods.UpdateImgRequest{
		UserId: req.UserId,
		Img:    req.Img,
		Mobile: req.Mobile,
		Code:   req.Code,
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msy:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msy:  "图片修改成功",
		Data: img,
	}, nil

}
